import React, { Component } from 'react'
import { Select } from 'antd'
import { getChannelList } from 'api/channel'

export default class Channel extends Component {
  state = {
    channelList: [] // 存储频道数据
  }
  render() {
    return (
      <div>
        <Select value={this.props.value} onChange={this.props.onChange} placeholder='请选择频道' style={{ width: 200, }}
          options={
            this.state.channelList.map(item => {
              return ({ value: item.id, label: item.name })
            })
          }
        />
      </div>
    )
  }
  // 获取频道列表数据
  async getChannelList() {
    const res = await getChannelList()
    this.setState({
      channelList: res.data.channels
    })
  }
  componentDidMount() {
    this.getChannelList()
  }
}
